<?php
namespace app\admin\middleware;
use think\facade\Session;
use  app\Jump;
use think\wenhainan\Auth as ActionAuth;
Class Auth{
    use Jump;
    public function handle($request, \Closure $next)
    {

        $this->checkAuth($request);
        return $next($request);
    }
    /**
     * 权限检查
     * @return bool
     */
    protected function checkAuth($request)
    {

        $controller = $request->controller();
        $action = $request->action();
        $auth = new ActionAuth();
        if( !session('admin_id')){
            $result = [
                'code' => 3,
                'msg' => "登录已过期",
                'url' => "/admin/index",
            ];
            return  json($result);
        }
        if( session('admin_id')!=1&&!$auth->check($controller . '-' . $action, session('admin_id'))){
            $this->error('你没有权限访问');
        }

    }

}